<?php

include_once 'Retriever.php';
//include_once '../Utility/simplehtmldom/simple_html_dom.php';
include_once '../InfoManager/Constants.php';
include_once '../AtacAPI/News.php';

class ACNews extends Retriever {
 
	private static $sections = '4'; //numero delle sezioni delle news
	private static $url = "http://muovi.roma.it/news/categoria"; //url delle news
	
	
	function __construct() {
	}
	
	function getNewsAtacAPI() 
	{	
		$out = array();
		$acnews = new News();
		$out_news = $acnews->getNews();

		foreach($out_news as $o){
        		$out[] = array("id"=>$o->getIdNews(), "title"=>$o->getTitle(), "message"=>$o->getMsg());
		}
		return $out;
	}
	function getNews(){
		return $this->getNewsAtacAPI();
/*
		$out=array();
		for($i=1;$i<=ACNews::$sections;$i++){
			$currUrl = ACNews::$url."/$i";
			$page = $this->getHTMLPageFromURL($currUrl);
			$html = str_get_html($page);
			$text = $html->plaintext;
			foreach ($html->find("p.indented a") as $el)
	    	$links[]="www.muovi.roma.it".$el->href;
		}
		

		foreach($links as $l){
			$page = $this->getHTMLPageFromURL($l);
			$html = str_get_html($page);
			$text = $html->plaintext;
			foreach ($html->find("div[id=main]/div") as $el) {
				$chunks = explode("?",$l);
				$chunks2 = explode("/",$chunks[0]);
				$id = $chunks2[count($chunks2)-1];
				$title = trim(htmlspecialchars_decode($el->children(0)->innertext,ENT_QUOTES));
				$msg = trim(htmlspecialchars_decode($el->children(1)->innertext,ENT_QUOTES));
				$out[] = array("id"=>$id,"title"=>$title,"message"=>$msg);
				//mysql_query("replace ifermata_news set id=$id, title='$title', message='$msg'",$db);
			}   
		}
		return $out;
*/
	}
	
}
?>
